package com.jcommander.model;

import java.io.File;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;

import javax.swing.filechooser.FileSystemView;


public class FileSystemRow {
	public static final String DIR_STRING = "<DIR>";
	
	private final FileSystemView fsv = FileSystemView.getFileSystemView();
	private final IconLabel iconLabel;
	private final String extension;
	private final String sizeTxt;
	private final String date;
	private int Id; //only to identify in table
	
	public FileSystemRow(File file) {
		iconLabel = new IconLabel(fsv.getSystemIcon(file), fsv.getSystemDisplayName(file));
		
		String filename = file.getPath();
		int pos = filename.lastIndexOf(".");
		extension = (pos > -1) ? filename.substring(pos) : "";
		
		NumberFormat numberFormatter = NumberFormat.getInstance(Locale.FRENCH);
		
		sizeTxt = file.isFile() ? numberFormatter.format((file.length())) : DIR_STRING;
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		date = dateFormat.format(file.lastModified());
		
	}
	
	public FileSystemRow(IconLabel iconLabel, String extension, String size, String date) {
		this.iconLabel = iconLabel;
		this.extension = extension;
		this.sizeTxt = size;
		this.date = date;
	}
	
	public IconLabel getIconLabel() {
		return iconLabel;
	}

	public String getExtension() {
		return extension;
	}

	public String getSize() {
		return sizeTxt;
	}

	public String getDate() {
		return date;
	}
	
	public int getId() {
		return Id;
	}
	
	public void setId(int id) {
		this.Id = id;
	}
}
